﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace WpfAdvControls.StatusPanel
{
    [ValueConversion(typeof (bool), typeof (Brush))]
    public class BoolBrushConverter : IValueConverter
    {
        public BoolBrushConverter(Brush trueBrush, Brush falseBrush)
        {
            TrueBrush = trueBrush;
            FalseBrush = falseBrush;
        }

        public BoolBrushConverter()
            : this(new SolidColorBrush(Colors.Green), new SolidColorBrush(Colors.Red))
        {
        }

        public Brush TrueBrush { get; set; }
        public Brush FalseBrush { get; set; }

        public object Convert(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            if ((value != null) && ((bool) value))
            {
                return TrueBrush;
            }
            return FalseBrush;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            if (value == TrueBrush)
            {
                return true;
            }
            return false;
        }
    }
}